package com.mikao.service.impl;

import com.mikao.dao.OfferPriceDao;
import com.mikao.dto.bo.ReqDataTableDto;
import com.mikao.dto.bo.TreePriceForm;
import com.mikao.dto.vo.RspDataTableDto;
import com.mikao.entity.OfferPrice;
import com.mikao.service.OfferPriceService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author kenny
 */

@Service
public class OfferPriceServiceImpl implements OfferPriceService {

    private OfferPriceDao offerPriceDao;

    public OfferPriceServiceImpl(OfferPriceDao offerPriceDao) {
        this.offerPriceDao = offerPriceDao;
    }

    @Override
    public RspDataTableDto<OfferPrice> offerPriceList(ReqDataTableDto reqDataTableDto) {
        List<OfferPrice> list = offerPriceDao.findAll();
        return new RspDataTableDto<>(reqDataTableDto.getDraw(), (long) list.size(), list);
    }

    @Override
    public void changePrice(TreePriceForm treePriceForm) {
        if (!ObjectUtils.isEmpty(treePriceForm.getId())) {
            OfferPrice one = offerPriceDao.findOne(treePriceForm.getId());
            one.setPrice(treePriceForm.getRecyclePrice());
            offerPriceDao.saveAndFlush(one);
        }
    }
}
